#include<iostream>
#include<map>
#include<string>
#include<cstring>
using namespace std;

const int maxn = 10 + 1;
const int maxm = 10000 + 10;
map<string,int> mp;


int predict[maxn];
int seq[maxm];
int n,k;
int no = 0;

int ID(string &s){
    if(mp.count(s))
        return mp[s];
    else{
        return mp[s] = no++;;
    }
}

int dp[maxn][maxm]; // dp[i][j+1]表示在前j序列中包含了前i预测的数量

void solve(){
    memset(dp,0,sizeof(dp));
    for(int i=0;i<k;i++){
        if(predict[0] == seq[i]){
            if(i>0){
                dp[0][i] =  dp[0][i-1] + 1;
            }
            else{
                dp[0][i] = 1;
            }
        }
        else{
            if(i>0) dp[0][i] = dp[0][i-1];
            else
                dp[0][i] = 0;
        }
    }

    for(int i=1;i<n;i++){
        for(int j=0;j<k;j++){
            if(i>j) dp[i][j] = 0;
            else if(predict[i] != seq[j])
                dp[i][j] = dp[i][j-1];
            else
                dp[i][j] = dp[i][j-1] + dp[i-1][j-1];
            dp[i][j] %= 1919810LL;
        }
    }
    cout << dp[n-1][k-1] << endl;
}
int main(){

    freopen("data.in","r",stdin);
    freopen("data.out","w",stdout);
    // read input
    int T;
    cin >> n >> T;
    string w;
    for(int i=0;i<n;i++){
        cin >> w;
        predict[i] = ID(w);
    }
    k = 0;
    while(T--){
        cin >> w;
        if(mp.count(w)) seq[k++] = mp[w];
    }
    solve();

    return 0;

}